package vincent.com.layouttest;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Created by chenzhengwen on 2015/9/21.
 */
public class GestureDetectActivity extends AppCompatActivity implements View.OnTouchListener{
    private final String TAG = "GestureDetectActivity";
    private float lastX, lastY;
    private TextView txt;
    private LinearLayout container;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gesture_detect);
        container = (LinearLayout)findViewById(R.id.container);
        container.setOnTouchListener(this);
        txt = (TextView)findViewById(R.id.txt);
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        lastX = event.getX();
        lastY = event.getY();

        txt.setX(lastX);
        txt.setY(lastY);
        int[] loc = new int[2];
        txt.getLocationInWindow(loc);
        Log.i(TAG, "mScreenX=" + loc[0] + " | mScreenY=" + loc[1]);
        return true;
    }
}
